<ui:composition template="/template/LayoutPadrao.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core">

	<ui:define name="titulo">#{cadastroPessoaBean.editar ? msg.editingPerson : msg.newPerson}</ui:define>

	<ui:define name="conteudo">
		<f:metadata>
			<f:viewParam name="codigo" value="#{cadastroPessoaBean.pessoa}" />
		</f:metadata>

		<h1>#{cadastroPessoaBean.editar ? msg.editingPerson : msg.newPerson}</h1>
		<h:form>
			<h:button value="#{msg.newBtn}" outcome="NovaPessoa" />
			<h:button value="#{msg.searchBtn}"
				outcome="ConsultaPessoas.xhtml?faces-redirect=true" 
				rendered="#{request.isUserInRole('consulta')}"/>
		</h:form>
		<h:form id="frm">

			<h:messages showDetail="false" showSummary="true"
				styleClass="form-messages" errorClass="error" infoClass="info" />
			<h:panelGrid columns="2" styleClass="form-grid"
				columnClasses="label, campo">
				<h:outputLabel value="#{msg.name}" />
				<h:inputText size="50" required="true" label="Nome"
					value="#{cadastroPessoaBean.pessoa.nome}" />

				<h:outputLabel value="#{msg.type}" />
				<h:selectOneRadio required="true" label="Tipo"
					value="#{cadastroPessoaBean.pessoa.tipo}"
					valueChangeListener="#{cadastroPessoaBean.mudancaTipo}"
					onchange="submit()" immediate="true">
					<f:selectItems value="#{cadastroPessoaBean.tiposPessoa}" var="tipo"
						itemLabel="#{tipo.descricao}" itemValue="#{tipo}" />
				</h:selectOneRadio>

				<h:outputLabel value="E-mail" />
				<h:inputText size="50" required="true" label="E-mail"
					value="#{cadastroPessoaBean.pessoa.email}">
					<f:validator
						validatorId="com.algaworks.cursojsf2.financeiro.validator.Email" />
				</h:inputText>

				<h:outputLabel value="#{msg.birthday}"
					rendered="#{cadastroPessoaBean.tipoFisico}" />
				<h:inputText size="15" label="Data de Nascimento"
					value="#{cadastroPessoaBean.pessoa.dataNascimento}"
					rendered="#{cadastroPessoaBean.tipoFisico}" required="true">
					<f:convertDateTime pattern="dd/MM/yyyy" locale="pt_BR"
						timeZone="GMT-3" />
				</h:inputText>

				<h:outputLabel value="#{msg.activityField}"
					rendered="#{cadastroPessoaBean.tipoJuridico}" />
				<h:selectOneMenu label="#{msg.activityField}"
					value="#{cadastroPessoaBean.pessoa.ramo}"
					rendered="#{cadastroPessoaBean.tipoJuridico}" required="true">
					<f:selectItem itemLabel="#{msg.selectOpt}" noSelectionOption="true" />
					<f:selectItems var="ramo" value="#{cadastroPessoaBean.atividades}"
						itemLabel="#{ramo.descricao}" itemValue="#{ramo}" />
				</h:selectOneMenu>

				<h:outputText></h:outputText>

				<h:commandButton value="#{msg.saveBtn}"
					action="#{cadastroPessoaBean.gravar}">
					<f:ajax render="@all" execute="@form" />
				</h:commandButton>

			</h:panelGrid>
		</h:form>

	</ui:define>

</ui:composition>

